001    /* $RCSfile: LoggerUtil.java,v $
002     * $Revision: 1.2 $
003     * $Date: 2002/11/23 11:09:57 $
004     * $Author: uwe_guenther $
005     * $State: Exp $
006     *
007     * Created on January 11, 2002 10:23 AM
008     *
009     * Copyright (C) 2001 Uwe Guenther <uwe@cscc.de>
010     *
011     * This file is part of the jhbci JCE-ServiceProvider. The jhbci JCE-
012     * ServiceProvider is a library, written in JavaTM, that should be 
013     * used in HBCI banking applications (clients and may be servers),
014     * to do cryptographic operations.
015     *
016     * The jhbci library is free software; you can redistribute it and/or
017     * modify it under the terms of the GNU Lesser General Public
018     * License as published by the Free Software Foundation; either
019     * version 2.1 of the License, or (at your option) any later version.
020     *
021     * The jhbci library is distributed in the hope that it will be useful,
022     * but WITHOUT ANY WARRANTY; without even the implied warranty of
023     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
024     * Lesser General Public License for more details.
025     *
026     * You should have received a copy of the GNU Lesser General Public
027     * License along with this library; if not, write to the Free Software
028     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
029     *
030     */
031    
032    package de.cscc.crypto.util;
033    
034    import java.util.logging.ConsoleHandler;
035    import java.util.logging.Handler;
036    import java.util.logging.Level;
037    import java.util.logging.Logger;
038    
039    /** 
040     * LoggerUtil Class.
041     *
042     * @author  <a href=mailto:uwe@cscc.de>Uwe Günther</a>
043     *
044     * @version $Revision: 1.2 $
045     */
046    public class LoggerUtil {
047    
048        /** Don't create new LoggerUtil, because its a wrapper for static methods.*/
049        private LoggerUtil() {
050        }
051    
052        public static Logger setConsoleLogging(String category, Level level) {
053            if (category == null) {
054                throw new NullPointerException("Parameter category is null.");
055            }
056            if (level == null) {
057                throw new NullPointerException("Parameter level is null.");
058            }
059            
060            //Switch _all_ global Handlers off.
061            Handler[] handlers = Logger.getLogger("").getHandlers();
062            for(int i = 0; i < handlers.length; i++) {
063                handlers[i].setLevel(Level.OFF);
064            }       
065            
066            //Setup the Logger for 'category'.
067            Logger log = Logger.getLogger(category);
068            
069            //Set the logger to the Level 'level'.
070            log.setLevel(level);
071            
072            //Create and add the ConsoleHandler.
073            Handler consoleHandler = new ConsoleHandler();
074            consoleHandler.setLevel(level);
075            log.addHandler(consoleHandler);     
076            
077            return log;
078        }    
079    }